********************************************************************************
* Voters
********************************************************************************

use dataset_voters, clear

egen nyears = count(turnout), by(anid)
keep if nyears == 4
gen post = 1 if year == 2012
replace post = 0 if year == 2000
gen anyfrackingXpost = anyfracking*post
tabulate year, gen(year_)
forvalues i=2(1)4 {
	gen anyfrackingXyear`i' = anyfracking * year_`i'
}

eststo clear

eststo: areg turnout lnwells year_*, a(anid) cl(zipcode)
estadd local VFE = "Yes"
estadd local YFE = "Yes"
eststo: areg turnout anywells year_*, a(anid) cl(zipcode)
estadd local VFE = "Yes"
estadd local YFE = "Yes"
eststo: areg turnout post anyfrackingXpost, a(anid) cl(zipcode)
estadd local VFE = "Yes"
estadd local YFE = "Yes"
eststo: areg turnout year_* anyfrackingXyear2 anyfrackingXyear3 ///
	anyfrackingXyear4, a(anid) cl(zipcode)
estadd local VFE = "Yes"
estadd local YFE = "Yes"

keep if highf==1
eststo: areg turnout lnwells year_*, a(anid) cl(zipcode)
estadd local VFE = "Yes"
estadd local YFE = "Yes"
eststo: areg turnout anywells year_*, a(anid) cl(zipcode)
estadd local VFE = "Yes"
estadd local YFE = "Yes"
eststo: areg turnout post anyfrackingXpost, a(anid) cl(zipcode)
estadd local VFE = "Yes"
estadd local YFE = "Yes"
eststo: areg turnout year_* anyfrackingXyear2 anyfrackingXyear3 ///
	anyfrackingXyear4, a(anid) cl(zipcode)
estadd local VFE = "Yes"
estadd local YFE = "Yes"

label variable lnwells "Log wells"
label variable anywells "Any wells"
label variable anyfrackingXpost "Ever fracked X post"
local k = 2004
forvalues i=2(1)4 {	
	label variable anyfrackingXyear`i' "Ever fracked X `k'"
	local k = `k' + 4
}

#delimit;

esttab
	using "_output/tableA8a.tex"
	,
		replace
		booktabs
		order(lnwells anywells anyfrackingXpost anyfrackingXyear2
		anyfrackingXyear3 anyfrackingXyear4)
		drop(year_* post _cons)
		cells(b(fmt(3) star) se(par))
		compress
		label
		gap
		collabels(none)
		nomtitles
		width(\linewidth)
		mgroups(
			"All states" "High-fracking states", 
			pattern(1 0 0 0 1 0 0 0)
			prefix(\multicolumn{@span}{c}{) suffix(})
			span erepeat(\cmidrule(lr){@span})
		)	
		stats(
			YFE
			VFE
			N_clust
			N
			,
				label(
					"Year fixed effects"
					"Voter fixed effects" 
					"Clusters"
					"Observations"
				)
				fmt(0 %20.0fc)
		)
		;
	
#delimit cr

********************************************************************************
* Donors
********************************************************************************

use dataset_donors, clear
egen nyears = count(ltotamount), by(cid)
keep if nyears == 8

gen post = 1 if year == 2012
replace post = 0 if year == 2000
gen anyfrackingXpost = anyfracking*post
tabulate year, gen(year_)
forvalues i=2(1)8 {
	gen anyfrackingXyear`i' = anyfracking * year_`i'
}

eststo clear

eststo: areg ltotamount lnwells year_*, a(cid) cl(zipcode)
estadd local DFE = "Yes"
estadd local YFE = "Yes"
eststo: areg ltotamount anywells year_*, a(cid) cl(zipcode)
estadd local DFE = "Yes"
estadd local YFE = "Yes"
eststo: areg ltotamount post anyfrackingXpost, a(cid) cl(zipcode)
estadd local DFE = "Yes"
estadd local YFE = "Yes"
eststo: areg ltotamount year_* anyfrackingXyear2 anyfrackingXyear3 ///
	anyfrackingXyear4 anyfrackingXyear5 anyfrackingXyear6 ///
	anyfrackingXyear7 anyfrackingXyear8, a(cid) cl(zipcode)
estadd local DFE = "Yes"
estadd local YFE = "Yes"

keep if highf==1
eststo: areg ltotamount lnwells year_*, a(cid) cl(zipcode)
estadd local DFE = "Yes"
estadd local YFE = "Yes"
eststo: areg ltotamount anywells year_*, a(cid) cl(zipcode)
estadd local DFE = "Yes"
estadd local YFE = "Yes"
eststo: areg ltotamount post anyfrackingXpost, a(cid) cl(zipcode)
estadd local DFE = "Yes"
estadd local YFE = "Yes"
eststo: areg ltotamount year_* anyfrackingXyear2 anyfrackingXyear3 ///
	anyfrackingXyear4 anyfrackingXyear5 anyfrackingXyear6 ///
	anyfrackingXyear7 anyfrackingXyear8, a(cid) cl(zipcode)
estadd local DFE = "Yes"
estadd local YFE = "Yes"

label variable lnwells "Log wells"
label variable anywells "Any wells"
label variable anyfrackingXpost "Ever fracked X post"
local k = 2002
forvalues i=2(1)8 {	
	label variable anyfrackingXyear`i' "Ever fracked X `k'"
	local k = `k' + 2
}

#delimit;

esttab
	using "_output/tableA8b.tex"
	,
		replace
		booktabs
		order(lnwells anywells anyfrackingXpost anyfrackingXyear2
		anyfrackingXyear3 anyfrackingXyear4 anyfrackingXyear5 
		anyfrackingXyear6 anyfrackingXyear7 anyfrackingXyear8)
		drop(year_* post _cons)
		cells(b(fmt(3) star) se(par))
		compress
		label
		gap
		collabels(none)
		nomtitles
		width(\linewidth)
		mgroups(
			"All states" "High-fracking states", 
			pattern(1 0 0 0 1 0 0 0)
			prefix(\multicolumn{@span}{c}{) suffix(})
			span erepeat(\cmidrule(lr){@span})
		)	
		stats(
			YFE
			DFE
			N_clust
			N
			,
				label(
					"Year fixed effects"
					"Donor fixed effects" 
					"Clusters"
					"Observations"
				)
				fmt(0 %20.0fc)
		)
		;
	
#delimit cr
